<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

$query = "SELECT admin FROM users WHERE user_id = " . $_SESSION[ 'user_id' ];
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if( isset( $row[ 'admin' ] ) && $row[ 'admin' ] == 1 ) {
	$round_name = getPostValue( 'round_name' );
	$speed = getPostValue( 'speed' );
	$turns_inactive = getPostValue( 'turns_inactive' );
	$server_message = formatInputLetter( $_POST[ 'server_message' ] );
	$remove_news = getPostValue( 'remove_news' );
	$max_turn = getPostValue( 'max_turn' );
	$extra_turns = getPostValue( 'extra_turns' );
	$global_orders = getPostValue( 'global_orders' );
	$special_event_started = getPostValue( 'special_event_started' );
	$open_shop = getPostValue( 'open_shop' );
	if( isset( $open_shop ) && $open_shop == 'open_shop' ) {
		$open_shop = 1;
	}
	else {
		$open_shop = 0;
	}
	$game_running = getPostValue( 'game_running' );
	if( isset( $game_running ) && $game_running == 'game_running' ) {
		$game_running = 1;
	}
	else {
		$game_running = 0;
	}

	$startHour = getPostValue( 'start_hour' );
	$startDay = getPostValue( 'start_day' );
	$startMonth = getPostValue( 'start_month' );
	$startYear = getPostValue( 'start_year' );
	if( is_numeric( $startHour ) && is_numeric( $startDay ) && is_numeric( $startMonth ) && is_numeric( $startYear ) ) {
		$startTime = strtotime( " $startYear-$startMonth-$startDay $startHour:00" );
		$startTime --;
	}
	else {
		$startTime = 0;
	}

	$query = "UPDATE game " .
			"SET round_name = '$round_name', speed = '$speed', turns_inactive = '$turns_inactive', " .
			"server_message = '$server_message', remove_news = '$remove_news', max_turn = '$max_turn', " .
			"global_orders = '$global_orders', extra_turns = '$extra_turns', special_event_started = '$special_event_started', " .
			"open_shop = $open_shop, game_running = $game_running, start_time = $startTime";
	mysql_query( $query ) or die( "Query failed : " . mysql_error() );
	$_SESSION[ 'game_settings_status' ] = "Settings saved.";
	header( "Location: game_settings.php" );
}
else {
	$_SESSION[ 'admin' ] = 0;
	header( "Location: ../overview/overview.php" );
}
?>
